package com.spnice.sgsms.util;

import com.spnice.sgsms.enums.ResultEnum;

import java.io.Serializable;

public class WrappedResult<T> implements Serializable {
    private static final long serialVersionUID = 2842063978115287026L;
    private Boolean successful;
    private Integer code;
    private T resultValue;
    private String resultHint;

    public WrappedResult() {
    }

    public static <T> WrappedResult<T> successWrapedResult(T data) {
        return new WrappedResult<>(true, data, "成功", ResultEnum.SUCCESS.getCode());
    }

    public static <T> WrappedResult<T> successWrapedResult(T data, String resultHint) {
        return new WrappedResult<>(true, data, resultHint, ResultEnum.SUCCESS.getCode());
    }

    public static WrappedResult failedWrappedResult(ResultEnum resultEnum) {
        return new WrappedResult(false, resultEnum.getMsg(), resultEnum.getCode());
    }

    public static WrappedResult failedWrappedResult(int code, String exMessage) {
        return new WrappedResult(false, exMessage, code);
    }

    public static WrappedResult failedWrappedResult(String exMessage) {
        return new WrappedResult(false, exMessage, ResultEnum.ERROR.getCode());
    }

    public WrappedResult(boolean isSuccess, String resultHint, int code) {
        this.code = code;
        this.successful = isSuccess;
        this.resultHint = resultHint;
    }

    public WrappedResult(boolean isSuccess, T data, String resultHint, int code) {
        this.code = code;
        this.successful = isSuccess;
        this.resultValue = data;
        this.resultHint = resultHint;
    }

    public boolean isSuccessful() {
        return successful;
    }

    public void setSuccessful(boolean successful) {
        this.successful = successful;
    }

    public T getResultValue() {
        return resultValue;
    }

    public void setResultValue(T resultValue) {
        this.resultValue = resultValue;
    }

    public String getResultHint() {
        return resultHint;
    }

    public void setResultHint(String resultHint) {
        this.resultHint = resultHint;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
